<?php
class Callenges_model extends CI_Model{

    public function __construct(){
        parent::__construct();
        $this->load->database();
    }

    /**
     * get all callenge
     * @return mixed all array
     */
    public function get_all_callenge($per_page,$page_no){
        $this->db->order_by('call_time','desc');
        return $this->db->limit($per_page,$per_page*($page_no-1))->get('callenges')->result_array();
    }

    /**
     * get by callenge
     * @param $data array
     * @return mixed  by array
     */
    public function get_by_callenge($data){
        return $this->db->get_where('callenges',$data)->row_array();
    }

    public function get_callenge_num()
    {
        $this->db->select('count(call_id) sum');
        return $this->db->get('callenges')->row_array()['sum'];
    }
}